package hu.imind.phonecalc.entity;

import hu.imind.phonecalc.client.dto.Call;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION)
class CallData implements Serializable {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private String num;
    @Persistent
    private String name;
    @Persistent
    private Date date;
    @Persistent
    private int duration;
    @Persistent
    private float price;
    @Persistent
    private float total;
    @Persistent
    private String cat;

    public CallData(String num, String name, Date date, int duration, float price, float total, String cat) {
        this.num = num;
        this.name = name;
        this.date = date;
        this.duration = duration;
        this.price = price;
        this.total = total;
        this.cat = cat;
    }

    public CallData(Call call) {
        this.num = call.get("num");
        this.name = call.get("name");
        this.date = call.get("date");
        this.duration = call.get("duration");
        this.price = Float.parseFloat(call.get("price").toString());
        this.total = Float.parseFloat(call.get("total").toString());
        this.cat = call.get("cat");
    }

    public Call getCall() {
        Call call = new Call();
        call.set("num",     getNum());
        call.set("name",    getName());
        call.set("date",    getDate());
        call.set("price",   getPrice());
        call.set("total",   getTotal());
        call.set("cat",     getCat());
        call.set("duration",getDuration());
        return call;
    }

    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public String getNum() {
        return num;
    }
    public void setNum(String num) {
        this.num = num;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public int getDuration() {
        return duration;
    }
    public void setDuration(int duration) {
        this.duration = duration;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    public float getTotal() {
        return total;
    }
    public void setTotal(float total) {
        this.total = total;
    }
    public String getCat() {
        return cat;
    }
    public void setCat(String cat) {
        this.cat = cat;
    }

}
